
typedef enum
{
  ST_STOP= 0,
  ST_INIT= 1,
  ST_RUN= 2,
}DEVICE_STATE;

typedef struct
{
  DEVICE_STATE  state;
  s16 pos_set;
  s16 pos_step;
	s16 pos_out;
	uint8_t sta_cycl;
}EEV_SET;


typedef struct
{
	unsigned pdsr:1;		//Pd/Ps rate Lo
	unsigned pd:1;			//Pd Hi
	unsigned curr:1;		//Current Hi
	unsigned td:1;			//Td Hi
	unsigned ipm:1;
	unsigned nc:3;
}FORBID_BIT;


typedef union
{
	FORBID_BIT	bit;
	uint8_t byte;
}FORBID_SET;



typedef struct
{
	FORBID_SET forbit_inc;
	FORBID_SET forbit_dec;
	FORBID_SET force_inc;
	FORBID_SET force_dec;
}CMPR_FORCE_FORBIT;





typedef struct
{
  unsigned drv:1;   //
  unsigned ph_ubc:1;
	unsigned hac_hi:1;  //Ӳ������
	unsigned sac_hi:1;  //��������
  unsigned ac_ov:1;
  unsigned ac_uv:1;
	unsigned trsipm_hi:1;
  unsigned ac_scv:1;
  unsigned pfc_oc:1;
  unsigned pfc_other:1;
  unsigned pd_hi:1;
  unsigned ps_hi:1;
  unsigned ps_lo:1;
  unsigned td_hi:1;
  unsigned td_lo:1;
  unsigned tdsh_lo:1;
  unsigned pd_flt:1;
  unsigned ps_flt:1;
  unsigned td_flt:1;
  unsigned ts_flt:1;
	unsigned os_flt:1;
  unsigned fr_lo_pe_hi:1;
  unsigned imp_hi:1;
  unsigned comm:1;
  unsigned pd_lo:1;
  unsigned di_lo:1;
  unsigned di_hi:1;
  unsigned ac_hi:1;
  unsigned dc_hi:1;
	unsigned lk_phase;
	unsigned lk_rot;
	unsigned st_proc;	
	unsigned vol_proc;
	unsigned fan1_ofc;
	unsigned fan2_ofc;
}ERROR_BIT;



typedef struct
{
	uint8_t pfc_amp;  //ѹ������������������
	uint8_t cmpr_target; //ѹ����ת��ָ�ֵΪ0ʱ��λ���������
	uint8_t control_state;
	uint8_t cmpr_rps; //ѹ����ת��ָ�ֵΪ0ʱ��λ���������
	int8_t cmpr_acc_dec; //�Ӽ���ָ�1=����0.1hz/s��-1=����0.1hz/s
	uint8_t fan_1_rpm; //���ת�٣�ֵΪ0ʱ��λ���������
	uint8_t fan_2_rpm; //���ת�٣�ֵΪ0ʱ��λ���������
	uint32_t req_times;
	uint8_t Lastcmpr_target;
	uint8_t cmpr_freq_step;
}CMPR_REQ;

typedef struct
{
	uint8_t cmpr_rps;
	uint16_t current;
	uint16_t voltage_ac;
	uint16_t voltage_dc;
	uint16_t phase_curr;
	int16_t temp_ipm;
	uint32_t error_code;
	uint16_t error_codeH;
	uint16_t error_codeL;
	uint16_t error_pfcH;
	uint16_t error_pfcL;
	uint16_t pfc_version;
	uint16_t drv_version;
	uint32_t pfc_code;
  uint8_t pfc_state;
	uint16_t fan_1_rpm; //���ת��
	uint16_t fan_2_rpm; //���ת��
	uint16_t fan_1_code;
	uint16_t fan_2_code;
	uint32_t ack_times;
	uint8_t cmpr_ack_ot_times;
	uint8_t fan_ack_ot_times;
}CMPR_ACK;

typedef struct
{
  uint8_t stage;
  uint16_t stage_delay;
  uint16_t wait_count;
  uint16_t cancel_count;
}OIL_COLLECT;

#define CMPR_ERR_DRV		0x01FFFFFF
#define CMPR_ERR_PH_UBC	0x04000000	//Pahse Current Unbalance

#define CMPR_ERR_AC_OV	0x40000001	//AC Over Voltage
#define CMPR_ERR_AC_UV	0x40000002	//AC Under Voltage
#define CMPR_ERR_AC_SCV	0x40000004	//AC Sudden Change Voltage
#define CMPR_ERR_PFC_OC	0x40000008	//PFC Over Current
#define CMPR_ERR_PFC_OTHER 0xBFFFFFF0 // PFC Other error

#define IR_ERROR_RECORD_1      22
#define IR_ERROR_RECORD_2      23
#define IR_ERROR_RECORD_3      24
#define IR_ERROR_RECORD_4      25
#define IR_ERROR_RECORD_5      26
#define IR_ERROR_RECORD_6      27
#define IR_ERROR_RECORD_7      28
#define IR_ERROR_RECORD_8      29
#define IR_ERROR_RECORD_9      30
#define IR_ERROR_RECORD_10     31
#define IR_ERROR_RECORD_11     32
#define IR_ERROR_RECORD_12     33
#define IR_ERROR_RECORD_13     34
#define IR_ERROR_RECORD_14     35
#define IR_ERROR_RECORD_15     36

#define COMP_SPEED_ADD                   0xc
#define IREG_MAX                         200

#define HREG_PARAM_VERSION                199 // �����汾��
#define PARAMETER_VERSION                 0x0614
#define PARAMETER_DEFAULT_COUNT           113

#define FACTORY_TEST_TAG  0x55AA
#define SOFTWARE_VERSION  917

#define DI_CMPR_RUN    0
#define DI_LO_PRESS    1
#define DI_HI_PRESS    2
#define DI_REMOTE_ON    3
#define DI_FCTRY_TEST   4


#define DO_CHN_1	0
#define DO_CHN_2	1
#define DO_CHN_3	2
#define DO_CHN_4	3
#define DO_CHN_5	4
#define DO_CHN_6	5
#define DO_CHN_7	6
#define DO_CHN_8	7

//#define DO_FAN_SS_1    DO_CHN_2
//#define DO_FAN_SS_2    DO_CHN_3
#define DO_CMPR_HTR    DO_CHN_2
#define DO_VALVE_2    DO_CHN_4   //���ͷ�
#define DO_VALVE_1    DO_CHN_5   //��Һ��

#define  STEP1   0 
#define  STEP2   1

#define ERR_COMM    1  //err->comm

#define ERR_PD_FAULT  2  //err->pd_flt 5��
#define ERR_PS_FAULT  3  //err->ps_flt 5��
#define ERR_TD_FAULT  4  //err->td_flt
#define EER_TS_FAULT  5  //err->ts_flt

#define ERR_PD_HI    6  //err->pd_hi  41bar 5��
#define ERR_PS_HI    7  //err->ps_hi
#define ERR_PS_LO    8  //err->ps_lo
#define ERR_TD_HI    9  //err->td_hi  120��60��
#define ERR_TD_LO    10  //err->td_lo
#define ERR_TSSH_LO  11  //err->tssh_lo  5�� 3����
#define ERR_FRQ_LO_PD_HI  12  //err->fr_lo_pe_hi 30HZ 34bar
#define ERR_HARDAC_HI      13  //Ӳ��������
#define ERR_SOFTAC_HI      14 //����������
#define ERR_AC_UV      15  //err->ac_uv  //Ƿѹ����
#define ERR_AC_OV      16 //err->ac_ov    //��ѹ����
#define ERR_TRSIPM_HI   17 //IPM�¶ȳ��±���
#define ERR_PD_LO      18 //err->pd_lo ����ѹ����
#define ERR_DI_HI     19  //err->di_hi ��ѹ���ر���
#define ERR_DI_LO     20  //err->di_lo ��ѹ���ر���
#define ERR_DC_HI     21  //���β������ͣ��
#define ERR_IPM_HI    22 //IPM�¶ȸ�
#define ERR_OS_FAULT	23 //
#define ERR_LK_PHASE	24 //
#define ERR_LK_ROT		25 //
#define ERR_ST_PROC		26 //
#define ERR_VOL_PROC	27 //
#define ERR_FAN1_OFC	28 //
#define ERR_FAN2_OFC	29

//#define ERR_CMPR_DRV  13  //err->drv
//#define ERR_PH_UBC    14  //err->ph_ubc


//#define ERR_AC_SCV    17  //err->ac_scv
//#define ERR_PFC        18  //err->pfc_oc





//#define ERR_PFC_OTHER  22  
 



//#define ERR_DRV_0000_0001  30  
//#define ERR_DRV_0000_0002  31  
//#define ERR_DRV_0000_0004  32  
//#define ERR_DRV_0000_0008  33  
//#define ERR_DRV_0000_0010  34  
//#define ERR_DRV_0000_0020  35  
//#define ERR_DRV_0000_0040  36  
//#define ERR_DRV_0000_0080  37  
//#define ERR_DRV_0000_0100  38  
//#define ERR_DRV_0000_0200  39  
//#define ERR_DRV_0000_0400  40  
//#define ERR_DRV_0000_0800  41  
//#define ERR_DRV_0000_1000  42  
//#define ERR_DRV_0000_2000  43  
//#define ERR_DRV_0000_4000  44  
//#define ERR_DRV_0000_8000  45  
//#define ERR_DRV_0001_0000  46  
//#define ERR_DRV_0002_0000  47  
//#define ERR_DRV_0004_0000  48  
//#define ERR_DRV_0008_0000  49  
//#define ERR_DRV_0010_0000  50  
//#define ERR_DRV_0020_0000  51  
//#define ERR_DRV_0040_0000  52  
//#define ERR_DRV_0080_0000  53  
//#define ERR_DRV_0100_0000  54  

//#define ERR_PFC_0000_0001  64  
//#define ERR_PFC_0000_0002  65  
//#define ERR_PFC_0000_0004  66  
//#define ERR_PFC_0000_0008  67  
//#define ERR_PFC_0000_0010  68  
//#define ERR_PFC_0000_0020  69  
//#define ERR_PFC_0000_0040  70  
//#define ERR_PFC_0000_0080  71  
//#define ERR_PFC_0000_0100  72  
//#define ERR_PFC_0000_0200  73  
//#define ERR_PFC_0000_0400  74  
//#define ERR_PFC_0000_0800  75  
//#define ERR_PFC_0000_1000  76  
//#define ERR_PFC_0000_2000  77  
//#define ERR_PFC_0000_4000  78  
//#define ERR_PFC_0000_8000  79  
//#define ERR_PFC_0001_0000  80  
//#define ERR_PFC_0002_0000  81  
//#define ERR_PFC_0004_0000  82  
//#define ERR_PFC_0008_0000  83  
//#define ERR_PFC_0010_0000  84  
//#define ERR_PFC_0020_0000  85  
//#define ERR_PFC_0040_0000  86  
//#define ERR_PFC_0080_0000  87  
//#define ERR_PFC_0100_0000  88  
//#define ERR_PFC_0200_0000  89  
//#define ERR_PFC_0400_0000  90  
//#define ERR_PFC_0800_0000  91  
//#define ERR_PFC_1000_0000  92  
//#define ERR_PFC_2000_0000  93 




#define         ASD_UPDATE_DELAY 100  //Automatic selling Drink 
#define         ASD_TIMERS_DELAY 1000 //Done every second.


#define DEFROST_AUTO_DISABLE 	0
#define DEFROST_AUTO_ENABLE 	1

#define STATUS_STOP            0
#define STATUS_INIT            1
#define STATUS_AUTO            2  //���л��ߵȴ�����
#define STATUS_REPAIR          3

#define STATUS_AUTO_TIMER    2

#define  WATER_TEMP_CH  AD_INDEX_4

#define  INSIDER_PRESS_CH  AD_PRESS_3 //AD_PRESS_3   //0-5v

#define  FILTER_PRESS_CH  AD_PRESS_4    //0-5v
#define  SPARE_PRESS2_CH  AD_PRESS_5    //0-5v

#define  LEVEL_CH       AD_PRESS_2    //4//4-20mA
#define  FLOW_CH        AD_PRESS_1    //0-5v



#define  SERVICE_QUIT_COMMAND     0
#define  SERVICE_ABUTTONWATEROUT  1
#define  SERVICE_INJECT           2
#define  SERVICE_WATERIN          3
#define  SERVICE_WATEROUT         4
#define  SERVICE_TEMPSENSORCALI   5
#define  SERVICE_TEMPSENSORCALI_CONFIRM  6




#define RM_CMD_STOP  0
#define RM_CMD_START 1
#define RM_CMD_REPAIR 2
#define RM_CMD_SERFUNCT 3  //������

//#define DI_LOCAL_RUN DI_FDB1

//DI Input
#define 	DI_MICROSWITCH1		              0 //΢������1
#define 	DI_MICROSWITCH2		              1 //΢������1
#define 	DI_MICROSWITCH3		              2 //΢������1
#define 	DI_MICROSWITCH4		              3 //΢������1
#define 	DI_MICROSWITCH5		              4 //΢������1

//#define 	DI_SLIP	                      1

//DI Input
#define 	DI_SOLENOID		              1
#define 	DI_SLIP	                      3
#define 	DI_EXPAND_TEMP_SW             0  //����ʽ��еʽ�¶ȿ���
#define 	DI_HEATER_TEMP_SW	          2  //����Ƭ�¶ȼ�ⳬ�¿���





#define CONTROL_STOP 0x01
#define CONTROL_SLOW_INCREASE 0x02
#define CONTROL_FORBID_INCREASER 0x04
#define CONTROL_FORCE_DECREASE 0x08
#define CONTROL_FAST_DECREASE 0x10



//Pack status defs
#define PACK_OK		        0
#define PACK_TRIPPED        1
#define PACK_TRIPPED_STOP   2




extern int16_t InputReg[IREG_MAX];


#define	       RAPID_STERI_MODE  0
#define	       GENERAL_STERI_MODE  1
#define	       DISS_PREHEAT_MODE  2

#define	      PREHEAT_STERI_MODE  3
#define	      LIQUID_STERI_MODE  4




#define	     LEVEL_LOW  500   //20K

#define	     LEVEL_HIGH  500  //20K



#define LOCAL_STOP		1
#define LOCAL_RUN		0

#define STOP		0
#define AUTO		1
#define MANUAL		2

#define MANUAL_DEF	3


#define	    TEMP_DISABLE   0
#define	    CONTROL_TEMP   1
#define	    EVAP_TEMP   2

#define	    ALWAYS_RUN   0
#define	    ACCORD_COMP_RUN   1


//Capacity states
#define CONDENSOR_FAN_START	        0	
#define COMPRESSOR_START         	1	//Find a compressor available to start and energise unloading valve
#define COMPRESSOR_STOP 0
#define CONDENSOR_STOP  1
#define DECREASE_COMPLETE 2



#define TM_TDSH_CYCLE_SEC      0 //tm_tdsh_cycle_sec
#define TM_FORCE_INC_DEC_SEC   1 //tm_force_inc_dec_sec





#define COOLSTAGE1_DELAY  9//��ȴ�׶���ʱ1 ��



#define WATEROUTPUT3_DELAY 11//һ����ˮ���� ��ˮʱ���̵�����ʱ   ��


//#define WATEROUTPUT4_DELAY  12//һ����ˮ����  ѹ����������ʱ ��


//#define POWER_ON_DELAY	        13//�ϵ����ʱ ��
//#define WATEROUTPUT5_DELAY  14//һ����ˮ���� ��ˮʱ�ؼ̵�����ʱ  ��



#define DISCVAVLE_STOP_DELAY    18   //��������ʱ 4�� ��
//#define INLETVALVE_START_DELAY    19   //����������ʱ
#define COMPAER_PRESS_DELAY    20  //��׼ѹ��������ʱ ��

//#define OUT_WATER_DELAY    21  //ѹ���Ƚϼ��
#define WATEROUT_OVER_DELAY    22   //��ˮ�ȴ���ʱ ��

#define FINISH_DELAY    23   ////�����ȴ���ʱ 1�� ��

//#define COMPRESSOR_STOP_DELAY    24   //
#define PRINT_DELAY    25   // ��ӡ�����
#define  DISCVALUE_STOP_DELAY    26   // ��������ʱ ��

#define SOLENOID_DELAY    27   // ���߹��ȶ�ʱ��15��



#define PIPELEAKAGE_COMP_DELAY 29


#define  COOLSTAGE2_DELAY 30 //��ȴ�׶���ʱ2 ��



#define WATEROUTCOMPSTOP_DELAY  32//��ˮ�׶�ѹ����ͣ������ʱ

#define HEATSTAGE_DISC_STOP_DELAY  33//����2����2����������ʱ

#define SOLENOID_DELAY_ON 34
#define SOLENOID_DELAY_OFF 35


#define  SEVICETEMPCALI_DELAY  36

#define WATEROUT_KEEP_DELAY  37				     
#define DISCVALVE_ON_DELAY   38				 
#define DISCVALVE_OFF_DELAY  39


#define COOLWATERIN_CONTROL_DELAY1 40
#define COOLWATERIN_CONTROL_DELAY2 41


#define PREHEAT_DELAY  42
#define DRINGTIMER_DELAY  43

#define LOWCONTROL 0
#define HIGHCONTROL 1




















typedef struct
{
	
	  u8 Status;
      
    u8        WorkStatus; 
	  u8        SysStatus;  
    s16       ControlValue;	  
    u8        lastSysStatus;	
	 
	 u8 PIDPWMTimer1;  //PID�������� ��

	  u8  ControlMode;
	  u8 LastControlMode;

	
      u16  Version;

			
	
	u16   restMinute;
//	u8    HeatAction;
	//u8    bDefrostAutoFlag;
	u16   PowerOnWaitTimer;  //�ϻ��ȴ�ʱ����
	u16   AlarmWaitTimer;    //�����ȴ�ʱ����

	
	
	u16     DOOutput;
    
    u16 tm_tdsh_cycle_sec;
		u16 tm_force_inc_dec_sec;
    
	u16		Inputs;
	u16    LastInputs;

	u8 lastWorkStatus;
	u8 FinishFlag;
    u8  StartFlag;


	  /////////
        u16 RemoteCMD;
        u16  LastRemoteCMD;    
   


	
}PACK, *PPACK;








typedef struct
{
    u16 BAND;
  			    
	u16 INTERGRAL ;
				
	u16 DIFF_QUTIENT ;
	
	u16 PERIOD ;
	
}PID_PARAMETERS, *PIDPara;




extern u8 SetJDASDParamValue( u16  location   ,   s16 Value   );


extern u8 ASD_Control(	void	);


extern  void DZ_Control(	void	);


extern u8 Pack_Init(void);



extern s16 GetJDASDStatuesValue(u16 address);

extern u8 GetFactoryTest(void);




extern u8 GetSysStatus(void);





extern u8 Getfactory_test_stage(void);
extern u8 Getfactory_test_error(void);


extern u8 GetPowerOnFlag(void);




extern void ClearPowerOnFlag(void);
extern u8 GetSolenoidWeakflag(void);

extern uint8_t getNextError(void);

extern void Update_Comp_Ack(void);

